# Maintainer: Haroogan <Haroogan@gmail.com>

_realname=tor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.2.7
pkgrel=1
pkgdesc="Anonymizing overlay network (mingw-w64)"
url="https://www.torproject.org/"
license=('BSD')
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-libevent"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-ca-certificates")
options=('strip')
source=("https://dist.torproject.org/${_realname}-${pkgver}.tar.gz"{,.asc})
sha256sums=('06a1d835ddf382f6bca40a62e8fb40b71b2f73d56f0d53523c8bd5caf9b3026d'
            'SKIP')
validpgpkeys=('2133BC600AB133E1D826D173FE43009C4607B1FB') # Nick Mathewson <nickm@alum.mit.edu>

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  CPPFLAGS="-isystem ${MINGW_PREFIX}/include"
  CFLAGS="-pipe -O3 -fomit-frame-pointer -funroll-loops"
  LDFLAGS="-s -Wl,-s"
  "${srcdir}/${_realname}-${pkgver}/configure" \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --disable-seccomp \
    --disable-libscrypt \
    --enable-lzma \
    --enable-zstd

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/${_realname}-${pkgver}"

  install -D "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -d           "${pkgdir}${MINGW_PREFIX}/var/lib/tor"
}
